package net.lwf.jaxb.client.maths.fraction;

import java.util.List;

import net.lwf.jaxb.entity.Fraction;
import net.lwf.jaxb.service.maths.fraction.FractionDataService;
import net.lwf.jaxb.util.maths.fraction.FractionGenerator;
import net.lwf.jaxb.util.maths.fraction.FractionUtil;

public class FractionClient {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
/*		int gcf = FractionUtil.calcGCF(4, 16);
		System.out.println(gcf);
		Fraction one = new Fraction(2, 4);
		Fraction two = new Fraction(0, 2);
		System.out.println(FractionUtil.add(one, two));
		
		System.out.println(FractionUtil.reduce(one));
		
		//Calculate LCM
		System.out.println("==> LCM for 3 and 9: " + FractionUtil.lcm(3, 9));
		System.out.println("==> LCM for 2 and 3: " + FractionUtil.lcm(2, 3));
		int numb[] = {2, 3, 5, 8};
		System.out.println("==> LCM for 2, 3, 5, 8: " + FractionUtil.lcm(numb));
		
		//Calculate GCD
		System.out.println("==> GCD for 3 and 9: " + FractionUtil.gcd(3, 9));
		System.out.println("==> GCD for 2 and 3: " + FractionUtil.gcd(2, 3));
		int numb1[] = {2, 3, 5, 8};
		System.out.println("==> GCD for 2, 3, 5, 8: " + FractionUtil.gcd(numb));
		
		//Calculate GCF
		System.out.println("======> GCF for 4, 16: " + FractionUtil.gcf(4, 16));
		
		//From the Fraction Generator
		FractionGenerator generator = new FractionGenerator("1");
		for(int i=0; i<20; i++) {
			Fraction fraction = generator.generate(false);
			System.out.println("------> Generated Fraction: " + fraction.toString());
		}*/
		
//		int k = 1;
//	
//		System.out.println( k % 2); //even, remainder always 0
//		System.out.println(5 % 2);  //odd, remainder always 1
//		
//		int a = 16;
//		int b = 4;
//		
//		System.out.println("===========> Quotient: " + a/b + " AND remainder: " + a%b);
		
		FractionGenerator generator = null;
		
		
		//Generate odd fraction
		generator = new FractionGenerator("2", "simple");
		for(int i=0; i<10; i++) {
			Fraction fraction = generator.generate(false);
			System.out.println("==============> Odd denominator fraction: " + fraction.toString() + "; Decimal Fraction: " + fraction.getDecimalFraction());
		}
		System.out.println(" ");
		//Generate odd fraction
		generator = new FractionGenerator("3", "simple");
		for(int i=0; i<10; i++) {
			Fraction fraction = generator.generate(false);
			System.out.println("==============> Even denominator fraction: " + fraction.toString() + "; Decimal Fraction: " + fraction.getDecimalFraction());
		}
		System.out.println(" ");
		//Greater numerator and show mixed fraction
		generator = new FractionGenerator("4", "mixed");
		for(int i=0; i<10; i++) {
			Fraction fraction = generator.generate(false);
			System.out.println("==============> Greater numerator fraction: " + fraction.toString() + "; Decimal Fraction: " + fraction.getDecimalFraction());
		}
		System.out.println(" ");		

	
		//To Decimal Fraction
		Fraction fraction = FractionUtil.toFraction(3.56);
		System.out.println("==========> Converted fraction (from 3.56): " + fraction.toString());
		
		fraction = FractionUtil.toFraction(0.42);
		System.out.println("==========> Converted fraction: (from 0.42): " + fraction.toString());
		
		fraction = FractionUtil.toFraction(.33);
		System.out.println("==========> Converted fraction: (from 0.33): " + fraction.toString());
		
		System.out.println(" ");
		generator = new FractionGenerator("2", "simple");
		List<Fraction> eqDenFractions = generator.generateEqualDenominatorFraction(4, false);
		int nCounter = 1;
		for(Fraction fraction1: eqDenFractions) {
			System.out.println("==============> Equal Fraction - " + nCounter + " : " + fraction1.toString());
			nCounter++;
		}
		
		System.out.println(" ");	
		System.out.println("-----------------------> Generate multiple fractions - Simple");	
		for(int i=0; i<10; i++) {
			generator = new FractionGenerator("4", "arithmatics", "addition", "simple");
			List<Fraction> fractions = generator.generateArithmaticFractions(false);
			for(Fraction data: fractions) {
				System.out.println("============> Multiple fractions: " + data.toFraction());
			}
			System.out.println(" ");
		}
		
		System.out.println(" ");	
		System.out.println("-----------------------> Generate multiple fractions - medium");	
		for(int i=0; i<50; i++) {
			generator = new FractionGenerator("4", "arithmatics", "addition", "medium");
			List<Fraction> fractions = generator.generateArithmaticFractions(false);
			for(Fraction data: fractions) {
				System.out.println("============> Multiple fractions: " + data.toFraction());
			}
			System.out.println(" ");
		}
		
		System.out.println(" ");	
		System.out.println("-----------------------> Generate multiple fractions - Difficult");	
		for(int i=0; i<30; i++) {
			generator = new FractionGenerator("4", "arithmatics", "addition", "difficult");
			List<Fraction> fractions = generator.generateArithmaticFractions(false);
			for(Fraction data: fractions) {
				System.out.println("============> Multiple fractions: " + data.toFraction());
			}
			System.out.println(" ");
		}
		
		//Fraction operation types
		List<String> operationtypes = new FractionDataService().getOperationTypes("4", "arithmatics");
		for(String operationType: operationtypes) {
			System.out.println(operationType);
		}
		
		testSubtract();
		
	}
	
	private static void testSubtract() {
		for(int i=0; i<15; i++) {
		FractionGenerator generator = new FractionGenerator("4", "arithmatics", "subtraction", "simple");
		List<Fraction> fractions = generator.generateArithmaticFractions(false);
		StringBuffer sb = new StringBuffer();
		int nCounter = 1;
		for(Fraction data: fractions) {
			sb.append(data.toFraction());
			if(nCounter < fractions.size()) {
				sb.append(" - ");
			}
			nCounter++;
		}
		sb.append(" = ");
		sb.append(FractionUtil.reduce(FractionUtil.subtract(fractions.get(0), fractions.get(1))).toString());
		System.out.println(sb.toString());
		System.out.println(" ");
		}
	}

}
